package com.woniuxy.boss.bossassembly.apiimpl;


import com.woniu.api.MessageApi;
import com.woniu.form.MessageForm;
import com.woniuxy.Result;
import com.woniuxy.boss.bossassembly.model.BaMessage;
import com.woniuxy.boss.bossassembly.service.IBaMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 消息表 前端控制器
 * </p>
 *
 * @author HDC
 * @since 2021-05-24
 */
@RestController
@RequestMapping("/bossassembly/ba-message")
@Slf4j
public class BaMessageController implements MessageApi {
    @Autowired
    private IBaMessageService iBaMessageService;
    @Override
    public Result addMessage(MessageForm messageForm) {
        log.info("开始增加消息{}---",messageForm.getMessageContent());
        iBaMessageService.addMessage(messageForm);
        return Result.success("增加消息成功");
    }

    @Override
    public Result updateMessage(Integer messageId, String examine) {
        log.info("开始审核消息{}---",examine);
        iBaMessageService.updateMessage(messageId,examine);
        return Result.success("审核消息状态成功");
    }

    @Override
    public Result getMessage(String examine) {
        log.info("查询消息{}---", examine);
        List<BaMessage> message = iBaMessageService.getMessage(examine);
        if (message.isEmpty()) {
            return Result.fail("没有此类消息");
        }
            return Result.success(message);
    }
}

